package com.gxa.service.discrepancy.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.discrepancy.Device;
import com.gxa.entity.discrepancy.VisitorList;
import com.gxa.entity.discrepancy.search.DeviceSearchMap;
import com.gxa.mapper.discrepancy.DeviceMapper;
import com.gxa.service.discrepancy.DeviceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
    @Autowired
    private DeviceMapper mapper;
    @Override
    public PageInfo<Device> queryByPage(DeviceSearchMap map) {
        PageHelper.startPage(map.getPageNum(),map.getPageSize());//1.开启分页

        QueryWrapper<Device> wrapper = new QueryWrapper<>();//2.条件构造器 模拟写动态sql  或者在xml 中写
        if (!StringUtils.isAnyBlank(map.getDeviceName())) {
            wrapper.like("device_name", map.getDeviceName());
        }

        if(map.getDeviceStatus() != null){
            wrapper.eq("device_status",map.getDeviceStatus());
        }

        PageInfo<Device> pageInfo = new PageInfo<>(mapper.selectList(wrapper));//3.获取分页信息
        return pageInfo;
    }

    @Override
    public Set<String> getDevices() {
        return mapper.getDevices();
    }

    @Override
    public Set<String> getLocations() {
        return mapper.getLocations();
    }
}
